package com.sdhs.paas.rc.service;

import java.util.List;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.PageHelper;
import com.sdhs.paas.rc.bean.AppInfoFileBean;
import com.sdhs.paas.rc.bean.PaginationEntity;
import com.sdhs.paas.rc.repository.AppInfoFileMapper;
import com.sdhs.paas.sdk.base.common.BaseDao;
import com.sdhs.paas.sdk.base.common.BasePage;
import com.sdhs.paas.sdk.base.page.Page;
import com.sdhs.paas.sdk.core.PaasBaseException;
import com.sdhs.paas.sdk.core.mybatis.EnablePaasMybatis;

/**
* 描述：AppInfoFileService 服务接口
* @author kangjichang
* @date 2018-09-21
*/

@EnablePaasMybatis
@MapperScan("com.sdhs.paas.itims.repository")
@Service
public class AppInfoFileService extends BaseDao<AppInfoFileBean, AppInfoFileMapper, Integer>{
		@Override
		public String getMapperNamespace() {
			return AppInfoFileMapper.class.getName();
		}
		
		@Autowired
		private AppInfoFileMapper appInfoFileMapper;
		
		@SuppressWarnings("deprecation")
		public Page<AppInfoFileBean> getPageAppInfoFileList(BasePage pageRequest, AppInfoFileBean appInfoFileBean) {
			pageRequest.setFilters(appInfoFileBean);
			Page<AppInfoFileBean> page = pageQuery(pageRequest);
			return page;
		}
		
		@SuppressWarnings("deprecation")
		public PaginationEntity<AppInfoFileBean> getPageAppInfoFileListNew(BasePage pageRequest, AppInfoFileBean appInfoFileBean) {
			/**
			 * PageHelper 分页查询
			 * */
			com.github.pagehelper.Page<AppInfoFileBean> pageTotal = PageHelper.startPage(pageRequest.getPage(), pageRequest.getPageSize(),
	                true, false);
			List<AppInfoFileBean> list = appInfoFileMapper.getList(appInfoFileBean);
			PaginationEntity<AppInfoFileBean> paginationEntity = new PaginationEntity<AppInfoFileBean>(list,
	                (int) pageTotal.getTotal());
			return paginationEntity;
		}
		
		@Transactional(rollbackFor = Exception.class)
		public boolean saveAppInfoFile(AppInfoFileBean appInfoFileBean) {
			try {
				int count = appInfoFileMapper.insertAppInfoFile(appInfoFileBean);
				return count == 1;
			} catch (Exception e) {
				throw new PaasBaseException(e, "500", "数据库插入异常！");
			}
		}
	
		@Transactional(rollbackFor = Exception.class)
		public boolean updateAppInfoFile(AppInfoFileBean appInfoFileBean) {
			try {
				int count = appInfoFileMapper.updateAppInfoFile(appInfoFileBean);
				return count == 1;
			} catch (Exception e) {
				throw new PaasBaseException(e, "500", "数据库插入异常！");
			}
		}
	
		public AppInfoFileBean getAppInfoFileDetail(String id) {
			return appInfoFileMapper.getAppInfoFileDetail(id);
		}
		
		public boolean deleteAppInfoFile(AppInfoFileBean appInfoFileBean){
			return appInfoFileMapper.deleteAppInfoFile(appInfoFileBean)>0;
		}
		
      
}